﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Hosting.Class;
using HostingDomainWebsite;

namespace Hosting
{
    public partial class ChangePassword : System.Web.UI.Page
    {

        protected SiteMaster master;

        protected void Page_Load(object sender, EventArgs e)
        {
            master = Page.Master as SiteMaster;
            master.setCurrentNav("Account", "ChangePassword");
        }

        /*
         * 1    : success
         * 20   : Password input is null or not have value
         * 21   : Password is less than 5 character
         * 22   : Password is bigger than 100 character
         * 23   : Password is not valid, Valid: [a-zA-Z0-9@!#$\'%^&*`~]
         * 24   : Password and repassword is not match
         * 25   : Old Password is null or not have value
         * 26   : Old Password is not correct
         */
        protected void ChangePassword_Click(object sender, EventArgs e)
        {
            Users users = new Users();
            int isValid = users.changePassValid(Session["username"].ToString(), txtOldPassword.Value, txtPassword.Value, txtRePassword.Value);
            if (isValid == 1)
            {
                int isChangePassword = users.changePassword(Session["username"].ToString(), txtPassword.Value);
                if (isChangePassword == 0)
                {
                    master.getMessage("Password has changed!", "notification success png_bg");
                }
                else 
                {
                    master.getMessage("There is an error!", "notification error png_bg");
                }
            }
            else if (isValid == 20)
            {
                master.getMessageAttention("Password input is null or not have value");
            }
            else if (isValid == 21)
            {
                master.getMessageAttention("Password is less than 5 character");
            }
            else if (isValid == 22)
            {
                master.getMessageAttention("Password is bigger than 100 character");
            }
            else if (isValid == 23)
            {
                master.getMessageAttention("Password is not valid, Valid: [a-zA-Z0-9@!#$\'%^&*`~]");
            }
            else if (isValid == 24)
            {
                master.getMessageAttention("New Password and RePassword is not match");
            }
            else if (isValid == 25)
            {
                master.getMessageAttention("Old Password is null or not have value");
            }
            else if (isValid == 26)
            {
                master.getMessageAttention("Old Password is not correct");
            }
        }

    }
}